package com.huizu.goods.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.huizu.common.annotation.Log;
import com.huizu.common.enums.BusinessType;
import com.huizu.goods.domain.ShopNews;
import com.huizu.goods.service.IShopNewsService;
import com.huizu.common.core.controller.BaseController;
import com.huizu.common.core.domain.AjaxResult;
import com.huizu.common.utils.ShiroUtils;
import com.huizu.common.utils.poi.ExcelUtil;
import com.huizu.common.core.page.TableDataInfo;

/**
 * 店铺信息Controller
 * 
 * @author 
 * @date 2021-12-06
 */
@Controller
@RequestMapping("/shop/news")
public class ShopNewsController extends BaseController
{
    private String prefix = "shop/news";

    @Autowired
    private IShopNewsService shopNewsService;

    @RequiresPermissions("shop:news:view")
    @GetMapping()
    public String news()
    {
        return prefix + "/news";
    }

    /**
     * 查询店铺信息列表
     */
    @RequiresPermissions("shop:news:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShopNews shopNews)
    {
        startPage();
        List<ShopNews> list = shopNewsService.selectShopNewsList(shopNews);
        return getDataTable(list);
    }
    
    /**
     * 查询店铺信息列表
     */
    @RequiresPermissions("shop:news:list")
    @PostMapping("/list1")
    @ResponseBody
    public TableDataInfo list1(ShopNews shopNews)
    {
        startPage();
        shopNews.setId((long)ShiroUtils.getSysUser().getShopId());
        List<ShopNews> list = shopNewsService.selectShopNewsList(shopNews);
        return getDataTable(list);
    }

    /**
     * 导出店铺信息列表
     */
    @RequiresPermissions("shop:news:export")
    @Log(title = "店铺信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShopNews shopNews)
    {
        List<ShopNews> list = shopNewsService.selectShopNewsList(shopNews);
        ExcelUtil<ShopNews> util = new ExcelUtil<ShopNews>(ShopNews.class);
        return util.exportExcel(list, "店铺信息数据");
    }

    /**
     * 新增店铺信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存店铺信息
     */
    @RequiresPermissions("shop:news:add")
    @Log(title = "店铺信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShopNews shopNews)
    {
        return toAjax(shopNewsService.insertShopNews(shopNews));
    }

    /**
     * 修改店铺信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ShopNews shopNews = shopNewsService.selectShopNewsById(id);
        mmap.put("shopNews", shopNews);
        return prefix + "/edit";
    }

    /**
     * 修改保存店铺信息
     */
    @RequiresPermissions("shop:news:edit")
    @Log(title = "店铺信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShopNews shopNews)
    {
        return toAjax(shopNewsService.updateShopNews(shopNews));
    }

    /**
     * 删除店铺信息
     */
    @RequiresPermissions("shop:news:remove")
    @Log(title = "店铺信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shopNewsService.deleteShopNewsByIds(ids));
    }
}
